let vm = new Vue({
    el: '#app',  //选中整个main
    data: {
        userCount: 0,
        articleCount: 0,
        meetingCount: 0,
        option: {
            // 标题
            title: {
                text: '小标数据汇总'
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross',
                    label: {
                        backgroundColor: '#aaaaff'
                    }
                }
            },
            // 图表说明
            legend: {
                data: ['新增用户', '新增文章', '新开会议']
            },
            // 工具栏(图片另存为按钮)
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
            },
            // 布局
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [{
                type: 'category',
                boundaryGap: false,
                data: ["10.21", "10.22", "10.23", "10.24", "10.25", "10.26", "10.27", "10.28", "10.29"]
            }],
            yAxis: [{
                type: 'value'
            }],
            series: [{
                name: '新增用户',
                type: 'line',
                stack: '总量',
                areaStyle: {},
                data: [12, 15, 15, 14, 14, 45, 45, 14, 78]
            },
                {
                    name: '新增文章',
                    type: 'line',
                    stack: '总量',
                    areaStyle: {},
                    data: [15, 10, 12, 14, 12, 9, 10, 11, 8]
                },
                {
                    name: '新开会议',
                    type: 'line',
                    stack: '总量',
                    label: {
                        normal: {
                            show: true,
                            position: 'top'
                        }
                    },
                    areaStyle: {},
                    data: [8, 8, 9, 7, 9, 12, 13, 10, 11]
                }
            ]
        }
    },
    methods: {
        getCreateBy7Day: function () {
            axios.get("home/getCreateBy7Day").then(rs => {
                // console.log(rs.data.obj)
                let map = rs.data.obj;
                let user = map.user;
                let article = map.article;
                let meeting = map.meeting;
                this.userCount = user[user.length - 1].count;
                this.articleCount = article[article.length - 1].count;
                this.meetingCount = meeting[meeting.length - 1].count;
                //9天内用户注册变化
                for (let i = 0; i < user.length; i++) {
                    this.option.series[0].data[i] = user[i].count;
                    this.option.xAxis[0].data[i] = user[i].nowDate;
                    // console.log(user[i].count);
                    // console.log(this.option.series[0].data[i]);
                }
                //9天内用户文章变化
                for (let i = 0; i < article.length; i++) {
                    this.option.series[1].data[i] = article[i].count;
                }
                //9天内用户会议变化
                for (let i = 0; i < meeting.length; i++) {
                    this.option.series[2].data[i] = meeting[i].count;
                }
                console.log(this.option.series[0])
                this.init();
            }).catch(e => {
                layer.msg("错误了")
            })
        },
        init: function () {
            // 基于准备好的dom，初始化echarts实例
            var myChart = echarts.init(document.getElementById('main'));
            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(this.option);
        },
        getLoginUser: function () {
            let item = sessionStorage.getItem("user");
            if (item == undefined || item.length <= 0) {//session不存在
                axios.get("user/getLoginUser").then(rs => {
                    sessionStorage.setItem("user", JSON.stringify(rs.data.obj));
                }).catch(e => {
                    layer.msg("出错了");
                })
            }
        }
    },
    beforeMount: function () {
        this.getCreateBy7Day();
        this.getLoginUser();
    }
});